package lab03.test12;

import java.sql.*;

public class Test12 {
    public static void main(String[] args) {

        //3+1
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String sql1 = "select%from t_users";
        String sql2 = "select%from t_users where username='admin'";
        String sql3 = "select%from t_users where username='admin' and password='123456'";
        String sql4 = "select%from t_users where regsuter>10000000";

        try {
            Class.forName("com.mysql.jdbc.Driver");

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC&characterEncoding=utf-8",
                    "root",
                    "123456");
            resultSet = statement.executeQuery(sql4);
            while (resultSet.next()) {
                System.out.println(resultSet.getInt(1) + "/t");
                System.out.println(resultSet.getString(2) + "/t");
                System.out.println(resultSet.getString(3) + "/t");
                System.out.println(resultSet.getLong(4));
                System.out.println();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                resultSet.close();
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

